package work.jame.blog.service.impl;

import work.jame.blog.framework.exception.db.InsertDataBaseException;
import work.jame.blog.pojo.UserRiceGrainsLog;
import work.jame.blog.mapper.UserRiceGrainsLogMapper;
import work.jame.blog.service.UserRiceGrainsLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Jame
 * @since 2023-05-26
 */
@Service
public class UserRiceGrainsLogServiceImpl extends ServiceImpl<UserRiceGrainsLogMapper, UserRiceGrainsLog> implements UserRiceGrainsLogService {

    @Override
    public void saveIncreaseRiceGrainsLog(Long userId, Double increaseRiceGrainsNumber, String illustrate) {
        UserRiceGrainsLog userRiceGrainsLog = new UserRiceGrainsLog();
        userRiceGrainsLog.setUserId(userId);
        userRiceGrainsLog.setRiceGrainsNumber(increaseRiceGrainsNumber);
        userRiceGrainsLog.setIllustrate(illustrate);
        userRiceGrainsLog.setStatus(true);
        if (!this.save(userRiceGrainsLog)) {
            throw new InsertDataBaseException("插入用户米粒日志失败");
        }
    }

    @Override
    public void saveReduceRiceGrainsLog(Long userId, Double reduceRiceGrainsNumber, String illustrate) {
        UserRiceGrainsLog userRiceGrainsLog = new UserRiceGrainsLog();
        userRiceGrainsLog.setUserId(userId);
        userRiceGrainsLog.setRiceGrainsNumber(reduceRiceGrainsNumber);
        userRiceGrainsLog.setIllustrate(illustrate);
        userRiceGrainsLog.setStatus(false);
        if (!this.save(userRiceGrainsLog)) {
            throw new InsertDataBaseException("插入用户米粒日志失败");
        }
    }
}
